package com.servlet;

import com.dao.imp.FindCollectStatus;
import com.dao.imp.FindGoodsDaoImp;
import com.entity.GoodStatus;
import com.entity.User;
import com.sun.net.httpserver.HttpContext;
import net.sf.json.JSONObject;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author Mathison
 * @Title: ${NAME}
 * @Package: ${PACKAGE_NAME}
 * @Description: TODO
 * @date 2021/11/25 16:58
 **/

@WebServlet(name = "GetColleStatusServlet", value = "/ColleStatusServlet")
public class ColleStatusServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int good_id = Integer.parseInt(request.getParameter("id"));
        HttpSession session = request.getSession();
        Object userId = session.getAttribute("userId");
        int user_id = Integer.parseInt(userId.toString());
        String sql = "SELECT * FROM user_collect WHERE user_id="+user_id+" AND good_id="+good_id;

        GoodStatus goodStatus = FindCollectStatus.getGoodStatus(sql);



        String jsonString = "{status:"+goodStatus.isStatus()+"}";

        JSONObject json = JSONObject.fromObject(jsonString);
        response.getWriter().print(json);
    }
}
